package com.define.commons.quartz;

import io.github.swagger2markup.GroupBy;
import io.github.swagger2markup.Language;
import io.github.swagger2markup.Swagger2MarkupConfig;
import io.github.swagger2markup.Swagger2MarkupConverter;
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
import io.github.swagger2markup.markup.builder.MarkupLanguage;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.net.URL;
import java.nio.file.Paths;

/**
 * 根据 Swagger2 生成 Markdown 文档
 * @Author xiewenlong
 * @Date 2018/11/27 16:46
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = CommonsQuartzApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class SwaggerDocs {

    @Value("${server.port}")
    String port;

    @Test
    public void generatorDocs() throws Exception{
        Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
                .withMarkupLanguage(MarkupLanguage.MARKDOWN)
                .withOutputLanguage(Language.ZH)
                .withPathsGroupedBy(GroupBy.TAGS)
                .withGeneratedExamples()
                .withoutInlineSchema()
                .build();
        Swagger2MarkupConverter.from(new URL("http://localhost:" + port+ "/v2/api-docs"))
                .withConfig(config)
                .build()
                .toFolder(Paths.get("docs/apis"));
    }
}
